#include "PreProcFileTests.hpp"
#include "ExpressionParserTests.hpp"
#include "MacroTests.hpp"
#include "TokenizerTests.hpp"
#include "TokenizerInputTests.hpp"
#include "../TokenizerInput.hpp"
#include "../PreProcessor.hpp"
#include "../../Shared/Shared.hpp"
#include <iostream>

int main()
{
  try
  {
    BuildNG::init_shared();
    CPreProc::init();

    /*Glib::RefPtr<Glib::IOChannel> io = Glib::IOChannel::create_from_file(
        "../../../TestFiles/gatomic.c","r");
    CPreProc::LineReader line_reader(io);

    Glib::RefPtr<CPreProc::PreProcFile> file = CPreProc::PreProcFile::parse(line_reader);
    CPreProc::PreProcessorContext ppc;
    file->process(ppc);

    Glib::RefPtr<CPreProc::DefineDirective> def = CPreProc::DefineDirective::parse(
      CPreProc::Tokenizer(" llaa(a,b,c)   ksr werhjw wery "),true);*/

    CPreProc::TokenizerTests::run_simple_test();
    CPreProc::TokenizerTests::run_pp_number_tests();
    CPreProc::TokenizerTests::run_test_from_standard_spec1();
    CPreProc::TokenizerTests::run_test_from_standard_spec2();

    CPreProc::MacroTests::test_define_parsing();
    CPreProc::MacroTests::test_parse_empty_replacement_list();
    CPreProc::MacroTests::test_macro_constructor1();
    CPreProc::MacroTests::test_macro_constructor2();
    CPreProc::MacroTests::test_no_macros();
    CPreProc::MacroTests::test_simple_replacement();
    CPreProc::MacroTests::test_collapse_whitespace();
    CPreProc::MacroTests::test_vararg_replacement();
    CPreProc::MacroTests::test_argument_list();
    CPreProc::MacroTests::test_space_before_arg_list();
    CPreProc::MacroTests::test_recursion_fusion();
    CPreProc::MacroTests::test_sharp_operator();
    CPreProc::MacroTests::test_double_sharp_operator();
    //CPreProc::MacroTests::test_double_sharp_operator_from_standard();
    CPreProc::MacroTests::test_replacement_list_equality();

    CPreProc::TokenizerInputTests::test_simple();
    CPreProc::TokenizerInputTests::test_get_begin_and_end();
    CPreProc::TokenizerInputTests::tests_from_standard_spec();
    CPreProc::TokenizerInputTests::test_trigraphs();
    CPreProc::TokenizerInputTests::test_get_source_location();

    CPreProc::PreProcFileTests tests;
    tests.test_ifdef();

    CPreProc::shutdown();
    BuildNG::shutdown_shared();

    return 0;
  }
  catch(const std::exception &err)
  {
    std::cout << "The following unhandled exception has been thrown: " << err.what() << std::endl;
    assert(!"Unhandled exception has been thrown.");
  }
  catch(const Glib::Exception &err)
  {
    std::cout << "The following unhandled exception has been thrown: " << err.what() << std::endl;
    assert(!"Unhandled exception has been thrown.");
  }
  catch(...)
  {
    assert(!"An exception of an unknown type has been thrown.");
  }

  return -1;
}

